package com.itheima.exception;

import org.springframework.stereotype.Component;
import org.springframework.web.bind.annotation.ControllerAdvice;
import org.springframework.web.bind.annotation.ExceptionHandler;
import org.springframework.web.bind.annotation.ResponseBody;

/**
 * @Description:
 * @Version: V1.0
 */
@Component
//设置当前类为异常处理器类
@ControllerAdvice
public class ExceptionAdvice {

    @ExceptionHandler(NullPointerException.class)
    @ResponseBody
    public String doNullException(Exception ex){
        return "空指针异常";
    }
    @ExceptionHandler(ArithmeticException.class)
    @ResponseBody
    public String doArithmeticException(Exception e){
        return "算数运算异常";
    }

    @ExceptionHandler(Exception.class)
    @ResponseBody
    public String doOtherException(Exception ex){
        return "出错了,请联系管理员";
    }
}
